package com.atguigu.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.entity.Permission;
import com.atguigu.service.PermissionService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/permission")
public class PermissionController  extends BaseController{
    @Reference
    private PermissionService permissionService;
    @RequestMapping
    public String index(Map map) {
        List<Permission> list = permissionService.findAllMenu();
        map.put("list",list);
        return "permission/index";
    }
//    去新增页面
    @RequestMapping("/create")
    public String goCreatePage(Map map,Permission permission){
        map.put("permission",permission);
        return "permission/create";
    }
//    新增
    @RequestMapping("/save")
    public String save(Permission permission){
        permissionService.insert(permission);
        return "common/successPage";
    }
//    去修改页面
    @RequestMapping("/edit/{id}")
    public String goEditPage(@PathVariable("id") Long id,Map map){
        Permission permission = permissionService.getById(id);
        map.put("permission",permission);
        return "permission/edit";
    }
//    修改
    @RequestMapping("/update")
    public String edit(Permission permission){
        permissionService.update(permission);
        return "common/successPage";
    }
//      删除
    @RequestMapping("/delete/{id}")
    public String deleted(@PathVariable("id") Long id){
        permissionService.delete(id);
        return "redirect:/permission";
    }
}
